package com.hksj.cm.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hksj.cm.dto.DeviceListDTO;
import com.hksj.cm.service.DeviceListService;
import com.hksj.cm.vo.DeviceVO;
import com.hksj.cm.vo.ParticleValueHistoryVO;
import com.hksj.common.core.model.Rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName DeviceListController
 * @Description TODO
 * @Author @陈章
 * @Date 2024/7/26 10:12
 * @Version 1.0
 */
@Api(tags = "设备列表")
@RestController
@RequestMapping("/api/deviceList")
public class DeviceListController {

    @Autowired
    private DeviceListService service;

    @ApiOperation(value = "根据楼层动态查询洁净度设备列表及属性值")
    @PostMapping("/queryDeviceMetadataParseInfo")
    public Rest<Page<DeviceVO>> queryDeviceMetadataParseInfo(@RequestBody DeviceListDTO dto) {
        Page<DeviceVO> page = service.queryDeviceMetadataParseInfo(dto);
        return Rest.ok(page);
    }

    @ApiOperation(value = "根据设备id查询设备粒子历史记录折线图{0代表最近24小时、1代表最近7天}")
    @GetMapping("/eqParticleValueHistory")
    public Rest<DeviceVO> eqParticleValueHistory(
            @ApiParam(value = "设备id", required = true) @RequestParam(required = true) String deviceId,
            @ApiParam(value = "时间区间", required = true, defaultValue = "0") @RequestParam(required = true, defaultValue = "0") int section) {
        DeviceVO device = service.eqParticleValueHistory(deviceId, section);
        return Rest.ok(device);
    }


    @ApiOperation(value = "根据设备id分页查询设备粒子历史记录{0代表最近24小时、1代表最近7天}")
    @GetMapping("/eqParticleValueHistoryList")
    public Rest<Page<ParticleValueHistoryVO>> eqParticleValueHistoryList(@ApiParam(value = "起始页", required = false, defaultValue = "1") @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                                         @ApiParam(value = "每页大小", required = false, defaultValue = "10") @RequestParam(required = false, defaultValue = "15") Integer pageSize,
                                                                         @ApiParam(value = "设备id", required = true) @RequestParam(required = true) String deviceId,
                                                                         @ApiParam(value = "时间区间", required = true, defaultValue = "0") @RequestParam(required = true, defaultValue = "0") int section) {
        Page<ParticleValueHistoryVO> page = service.eqParticleValueHistoryList(pageNum, pageSize, deviceId, section);
        return Rest.ok(page);
    }
}
